<!DOCTYPE html>
<html>

<head>

    {include file="common:meta"}

</head>
<style>
    .btn-primary{

    }

</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">

                <div class="ibox-content">
                    <form method="" class="form-horizontal" id="form" action="">
                        <div class="hr-line-dashed"></div>
                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label">*奖励类型</label>
                            <div class="col-sm-10">
                                <select class="form-control m-b" id="gift-type" name="reward_type">
                                    <option value="{$ruleData['reward_type']}" selected>{$ruleData['type_name']}</option>
                                    {volist name='return' id='gift'}
                                    <option value="{$gift['k']}">{$gift['v']}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group has-success" >
                            <label class="col-sm-2 control-label">*奖品名称</label>
                            <div class="col-sm-10">
                                <select class="form-control m-b" id="typed-id" name="reward_id">
                                    <option value="{$ruleData['reward_id']}" selected>{$ruleData['gift_name']}</option>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label">*礼物图片</label>
                            <div class="col-sm-10">
                                <input type="text" name="reward_img" value="{$ruleData['reward_img']}"  class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label">*自定义内容</label>
                            <div class="col-sm-10">
                                <input type="text" name="custom" value="{$ruleData['custom']}" disabled class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label">*奖励数量</label>
                            <div class="col-sm-10">
                                <input type="number" name="reward_number" value="{$ruleData['reward_number']}" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label">*奖励倍数</label>
                            <div class="col-sm-10">
                                <input type="number" name="reward_double"  value="{$ruleData['reward_double']}" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group has-success">
                            <label class="col-sm-2 control-label">*状态
                            </label>
                            <div class="col-sm-10">
                                <div class="radio">
                                    {if $ruleData['status']==0}
                                    <label><input type="radio"  name="status" value="0" checked> <i></i> 下架</label>
                                    {else /}
                                    <label><input type="radio"  name="status" value="0" > <i></i> 下架</label>
                                    {/if}
                                </div>
                                <div class="radio">
                                    {if $ruleData['status']==1}
                                    <label><input type="radio" name="status"  value="1" checked> <i></i> 上架</label>
                                    {else}
                                    <label><input type="radio" name="status"  value="1"> <i></i> 上架</label>
                                    {/if}
                                </div>
                            </div>
                        </div>

                            <div class="col-sm-10">
                                <input type="hidden" name="id"  value="{$ruleData['id']}" class="form-control">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group has-success">
                            <div class="col-sm-4 col-sm-offset-2">
                                <input class="btn btn-primary" id="btn-submit" type="button" value="提交">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="common:footer"}
<script>
    //同意修改
    var index = parent.layer.getFrameIndex(window.name);
    $('#btn-submit').click(function(){
        layer.confirm('确定修改吗？',{
            title:['提示','font-size:18px;font-family:楷体;font-weight:700;'],
            btn: ['确定','取消'] //按钮
        },function(){
            $.ajax({
                type:'get',
                url:'/SignRuleSubmitEdit',
                async:true,
                data:$('#form').serialize(),
                dataType:'json',
                success:function(result){
                    console.log(result);
                    if(result.code == 100){
                        //   parent.layer.close(index);//关闭当前页
                        layer.msg(result.msg,{
                            icon:1,
                            time:1000
                        });

                        //$('#tb_departments',parent.window.document).reload();
                        setTimeout(function () {
                            parent.layer.close(index);// 关闭layer
                        },1500);

                        //window.parent.parent.location.replace(location.href);
                        //$('#tb_departments',parent.window.document).bootstrapTable(('refresh'));

                        // window.parent.location.replace(location.href)//刷新父级页面
//                        $('#tb_departments').bootstrapTable(('refresh'));
//                        $('#batch-deal-with').css('display','none');
                    }
                    else{
                        layer.msg(result.msg,{
                            icon:2,
                            time:1000
                        });
                    }
                },
                error:function(err){
                    layer.msg('服务器开小差了！',{
                        time:1500
                    });
                }
            });
        });
    });
    //二级联动
    $(document).ready(function(e) {
        ChangeType();
        $("#gift-type").change(function(){
            ChangeType();
        });
        $("#typed-id").change(function(){
            ChangeGift();
        })
    });
    function ChangeType(){
        var giftType = $("#gift-type").val();
        console.log(giftType);
        $.ajax({
            async:false,
            url:"/SignRuleGiftName",
            data:{giftType:giftType},
            type:"post",
            dataType:"TEXT",
            success:function(res){
              //  var hang = data.split("|");
                var data = JSON.parse(res);

                console.log(data);
                var str = "<option value='' selected>--请选择--</option>";
                if(data != null){
                    for(var i in data){
                        str+= "<option value="+data[i]['id']+">"+data[i]['gift_name']+"</option>";
                    }
                    // for(var i=0;i<data.length;i++){
                    //     str += "<option value="+data[i].id+">"+data[i].gift_name+"</option>";
                    // }
                }

                $("#typed-id").html(str);
            }
        });
    }
    function ChangeGift(){
        var giftId = $("#typed-id").val();
        console.log(giftId);
    }

</script>
</body>

</html>